package com.zhijian.medical.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.format.FastDateFormat;
import com.zhijian.medical.config.CommonConfig;
import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.vo.request.FileSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.LoginMeetingSignVo;
import com.zhijian.medical.entity.vo.request.MeetingDataNewSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.MeetingDataNewSearchVo;
import com.zhijian.medical.entity.vo.response.CodeVo;
import com.zhijian.medical.entity.vo.response.MeetingDataNewCalendarVo;
import com.zhijian.medical.entity.vo.response.MeetingDataNewVo;
import com.zhijian.medical.enums.MeetingNewTypeEnum;
import com.zhijian.medical.holder.CurrentUserHolder;
import com.zhijian.medical.service.MeetingDataNewService;
import com.zhijian.response.annotation.Response;
import com.zhijian.util.page.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 会议表格数据 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-06-05 14:50:36
 */
@Slf4j
@Controller
@Api(tags = "会议表格数据（新）")
public class MeetingDataNewController {

    @Autowired
    private MeetingDataNewService service;

    @Autowired
    private CommonConfig commonConfig;

    /**
     * 获取最新编号
     *
     * @return
     */
    @Response
    @GetMapping("/meeting/data/new/code/{type}")
    @ApiOperation("获取最新编号")
    public CodeVo getNewCode(@PathVariable("type") Byte type) {
        CodeVo codeVo = new CodeVo();
        codeVo.setCode2(service.createNextCode(type));
        MeetingNewTypeEnum personTypeEnum = MeetingNewTypeEnum.getByCode(type.intValue());
        assert personTypeEnum != null;
        codeVo.setCode(personTypeEnum.getNumber());
        codeVo.setDw(commonConfig.getDw());
        codeVo.setVersion("D/0");
        codeVo.setSaveTime("3年");
        codeVo.setZrr("文件管理员");
        codeVo.setPublishDate(DateUtil.format(new Date(), FastDateFormat.getInstance("yyyy年MM月dd日")));
        codeVo.setExecuteDate(codeVo.getPublishDate());
        return codeVo;
    }

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/data/new")
    @ApiOperation("新增")
    public boolean insert(@RequestBody MeetingDataNewSaveOrUpdateVo param) {
        PersonDto user = CurrentUserHolder.getUser();
        param.setUserId(user.getId());
        param.setUserName(user.getName());
        param.setUserPhone(user.getPhone());
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.save(param);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/meeting/data/new/{id}")
    @ApiOperation("删除")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/meeting/data/new/{id}")
    @ApiOperation("修改")
    public boolean update(@PathVariable("id") Long id, @RequestBody MeetingDataNewSaveOrUpdateVo param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.modify(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/meeting/data/new/{id}")
    @ApiOperation("根据id查询")
    public MeetingDataNewVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/data/new/page")
    @ApiOperation("分页查询")
    public Page<MeetingDataNewVo> selectByCondition(@RequestBody(required = false) MeetingDataNewSearchVo param) {
        if (param == null)
            param = MeetingDataNewSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 列表查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/data/new/list")
    @ApiOperation("列表查询")
    public List<MeetingDataNewVo> selectList(@RequestBody(required = false) MeetingDataNewSearchVo param) {
        if (param == null)
            param = MeetingDataNewSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectList(param);
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    @Response
    @DeleteMapping("/meeting/data/new/list")
    @ApiOperation("批量删除")
    public boolean delete(@RequestBody(required = false) List<Long> idList) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), idList);
        service.deleteByIdList(idList);
        return true;
    }

    /**
     * 保存上传的PPT
     *
     * @param fileSaveOrUpdateVos
     * @return
     */
    @Response
    @PutMapping("/meeting/data/new/ppt/{id}")
    @ApiOperation("保存上传的PPT")
    public boolean saveFiles(@PathVariable("id") Long id, @RequestBody List<FileSaveOrUpdateVo> fileSaveOrUpdateVos) {
        return service.savePPT(id, fileSaveOrUpdateVos);
    }

    /**
     * 保存上传的照片
     *
     * @param fileSaveOrUpdateVos
     * @return
     */
    @Response
    @PutMapping("/meeting/data/new/pic/{id}")
    @ApiOperation("保存上传的照片")
    public boolean savePic(@PathVariable("id") Long id, @RequestBody List<FileSaveOrUpdateVo> fileSaveOrUpdateVos) {
        return service.savePic(id, fileSaveOrUpdateVos);
    }

    /**
     * 获取一个月的培训日历
     *
     * @param month
     * @return
     */
    @Response
    @GetMapping("/meeting/data/new/calendar")
    @ApiOperation("获取一个月的培训日历")
    public List<MeetingDataNewCalendarVo> getMeetingDataNewCalendarVoByMonth(@RequestParam(value = "month") String month) {
        return service.getMeetingDataNewCalendarVoByMonth(month);
    }

    /**
     * 输入工号密码签到
     *
     * @param loginVo
     * @return
     */
    @Response
    @PostMapping("/meeting/data/new/login/sign")
    @ApiOperation("输入工号密码签到")
    public boolean loginSign(@RequestBody LoginMeetingSignVo loginVo) {
        return service.loginSign(loginVo);
    }

}